package com.six.work.mapper;

import com.six.work.entity.Ad;
import com.six.work.entity.AdView;
import com.six.work.entity.Announcement;
import com.six.work.entity.AnnouncementView;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdMapper {
    @Select("SELECT ad.*,admin.admin_name FROM ad ad JOIN admin admin on ad.admin_id = admin.admin_id ORDER BY ad.ad_id DESC")
    List<AdView> findAllAd();

    @Select("SELECT * from ad where ad_id=#{ad_id}")
    Ad SelectAdByID(Integer ad_id);

    @Delete("DELETE from ad where ad_id=#{ad_id}")  //删除
    Integer DelAdByID(Integer ad_id);

    @Insert("insert into ad (ad_id,location,title,link,posted,admin_id) values(#{ad_id},#{location},#{title},#{link},#{posted},#{admin_id})")
    Integer insertAd(Ad ad);

    @Update("update ad set ad_id=#{ad_id},admin_id=#{admin_id},location=#{location},title=#{title},link=#{link},posted=#{posted} where ad_id=#{ad_id}")
    Integer updateAd(Ad ad);

    @Select("SELECT  ad.*,admin.admin_name FROM ad ad JOIN admin admin on ad.admin_id = admin.admin_id " +
            "WHERE ad.title like '%${adTitle}%' ORDER BY ad.ad_id DESC")
    List<AdView>  findAdByName(String adTitle);

    @Select("SELECT  ad.*,admin.admin_name FROM ad ad JOIN admin admin on ad.admin_id = admin.admin_id "+
            "WHERE ad.title like '%${adTitle}%' AND admin.admin_id=#{admin_id} ORDER BY ad.ad_id DESC")
    List<AdView> findAdByadIDAndannName(@Param("adTitle") String adTitle, @Param("admin_id") Integer admin_id);

    @Select("SELECT * FROM it.ad where location='求职者首页';")
    List<Ad> findAd();

    @Select("SELECT * FROM it.ad where location='招聘者关于我们';")
    List<Ad> findAd2();
}
